package de.hdodenhof.circleimageview.sample.ui.fragment.button;

import android.animation.Animator;
import android.animation.ObjectAnimator;
import android.animation.ValueAnimator;
import android.app.Activity;
import android.os.Bundle;
import android.util.Property;
import android.view.View;
import android.widget.TextView;

import de.hdodenhof.circleimageview.sample.R;

public class MyAnimatorButtonActivity extends Activity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_my_animator);
        final TextView textView = findViewById(R.id.text);
        final ValueAnimator animator = ValueAnimator.ofInt(10);
        final ValueAnimator fontSizeAnimator = ValueAnimator.ofFloat(1);

        fontSizeAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
            @Override
            public void onAnimationUpdate(ValueAnimator animation) {
                float scale = 2 * (1- (Float) animation.getAnimatedValue()) + 1;
                textView.setScaleX( scale);
                textView.setScaleY(scale);
            }
        });
        fontSizeAnimator.setDuration(1000);

        animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
            @Override
            public void onAnimationUpdate(ValueAnimator animation) {
                textView.setText(String.valueOf(animation.getAnimatedValue()));
            }
        });

        animator.addListener(new Animator.AnimatorListener() {
            @Override
            public void onAnimationStart(Animator animation) {

            }

            @Override
            public void onAnimationEnd(Animator animation) {
                textView.setText("结束");
                fontSizeAnimator.end();
            }

            @Override
            public void onAnimationCancel(Animator animation) {

            }

            @Override
            public void onAnimationRepeat(Animator animation) {

            }
        });

        textView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                animator.setDuration(5000);
                animator.setIntValues(0,5);
                animator.start();
                fontSizeAnimator.start();

            }
        });
    }
}
